package com.exercise.memberscheduling.repository.service;

import com.exercise.memberscheduling.domain.valueObject.Member;
import com.exercise.memberscheduling.domain.valueObject.MemberOperate;
import com.exercise.memberscheduling.repository.mapper.MemberMapper;
import com.exercise.memberscheduling.security.UserLogin;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
//串行化
@Transactional(isolation = Isolation.SERIALIZABLE)
public class MemberService {
    @Autowired
    private MemberMapper memberMapper;
    //单个会员添加课程
    public void addCoursesTimes(int addTimes,Member member,MemberOperate memberOperate){
        memberMapper.addCoursesTimes(addTimes,member);
        memberMapper.addOperateRecord(memberOperate);
    }
    //会员上1节课
    public void BeginClass(Member member,MemberOperate memberOperate){
        memberMapper.BeginClass(member);
        memberMapper.addOperateRecord(memberOperate);
    }
    //根据id查询单个会员信息
    public Member selectMemberLeftCourses(Member member)
    {
        return memberMapper.selectMemberLeftCourses(member);
    }
    //根据姓名查询会员信息
    public List<Member> selectMemberByName(Member member)
    {
        return memberMapper.selectMemberByName(member);
    }
    //查询所有会员的信息
    public List<Member> selAllMembers()
    {
        return memberMapper.selAllMembers();
    }
    //批量增加会员信息
    public void addMemberInfos(List<Member>members)
    {
        memberMapper.addMemberInfos(members);
    }
    //添加一个会员信息
    public void addMemberInfo(Member member)
    {
        memberMapper.addMemberInfo(member);
    }
    //查询所有操作记录
    public List<MemberOperate> selAllOperate()
    {
        return memberMapper.selAllOperate();
    }
    //根据用户查找操作记录
    public List<MemberOperate> selOperateByMemberName(Member member)
    {
        return memberMapper.selOperateByMemberName(member);
    }
    //更改会员姓名
    public void changeMemberName(Member member)
    {
        memberMapper.changeMemberName(member);
    }
    //修改会员的课程数
    public void reviseMemberCoursesTimes(Member member,MemberOperate memberOperate)
    {
        memberMapper.reviseMemberCoursesTimes(member);
        memberMapper.addOperateRecord(memberOperate);
    }
    //修改管理员密码
    public void reviseAdminPassword(String password)
    {
        memberMapper.reviseAdminPassword(password);
    }
    //查询管理员密码
    public UserLogin SelAdminPassword()
    {
        return memberMapper.SelAdminPassword();
    }
    //删除一个会员
    public void deleteMember(String memberId)
    {
        memberMapper.deleteMember(memberId);
    }
    //查询某一段时间内的操作记录
    public List<MemberOperate> selPeriodOperate(String startTime ,String endTime)
    {
        return memberMapper.selPeriodOperate(startTime,endTime);
    }
}
